import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
import Component from '../views/Component.vue'
import Admin from '../views/Admin.vue'




//按需加载  优化项目
const Lunbo =(resolve)=>{
  import('../views/Lunbo.vue').then( (module)=>{
    resolve(module)
  })
}
const Container =(resolve)=>{
  import('../views/Container.vue').then( (module)=>{
    resolve(module)
  })
}
const Icon =(resolve)=>{
  import('../views/Icon.vue').then( (module)=>{
    resolve(module)
  })
}
const User =(resolve)=>{
  import('../views/User.vue').then( (module)=>{
    resolve(module)
  })
}
const Architecture =(resolve)=>{
  import('../views/Architecture.vue').then( (module)=>{
    resolve(module)
  })
}
const Adminset =(resolve)=>{
  import('../views/Adminset.vue').then( (module)=>{
    resolve(module)
  })
}
const Scanning =(resolve)=>{
  import('../views/Scanning.vue').then( (module)=>{
    resolve(module)
  })
}


//admin页码



const routes = [
  
  {
    path: '/',
    component: Component,
    redirect: '/admin',  // 路由重定向
    children: [{
      path: 'lunbo',  // 不斜杠开头
      component: Lunbo
    },{
      path: 'container',  // 不斜杠开头
      component: Container
    },{
      path: 'icon',  // 不斜杠开头
      component: Icon
    },
    ,{
      path: 'user',  // 不斜杠开头
      component: User
    },
    ,{
      path: 'architecture',  // 不斜杠开头
      component: Architecture
    },
    ,{
      path: 'adminset',  // 不斜杠开头
      component: Adminset
    },
    ,{
      path: 'scanning',  // 不斜杠开头
      component: Scanning
    },
  
  ]},

  {
      path: '/admin',
      name:Admin,
      component: Admin,
  },


  {
    path: '*',   // 错误路由
    redirect: '/admin'   //重定向
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})



router.beforeEach((to,from,next)=>{
  let token = sessionStorage.getItem("admin")
  if(to.path!=="/admin"&&!token){
    next("/admin")
   return false
  }else{
    next()
  }
})
export default router
